/**
 * @Author: YangYun
 * @Date: 2020/7/27 15:38
 */
package pay

import (
	"context"
	"encoding/base64"
	"fmt"
	"net/url"
	"strconv"
	"strings"
	"time"

	"git.900sui.cn/kc/base/common/functions"
	"git.900sui.cn/kc/base/common/toolLib"
	"git.900sui.cn/kc/base/utils"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/rpcPay/common/lib"
	"git.900sui.cn/kc/rpcPay/common/models"
	_const "git.900sui.cn/kc/rpcPay/lang/const"
	bus2 "git.900sui.cn/kc/rpcinterface/client/bus"
	"git.900sui.cn/kc/rpcinterface/interface/bus"
	"git.900sui.cn/kc/rpcinterface/interface/order"
	pay2 "git.900sui.cn/kc/rpcinterface/interface/pay"
	"github.com/shopspring/decimal"
	"github.com/tidwall/gjson"
)

type ccb struct {
}

func (c *ccb) PayQr(payInfo *pay2.PayInfo) (string, error) {
	if c.checkIn(payInfo) {
		return lib.CcbPay.Qrurl(payInfo.OrderSn, payInfo.RealAmount, kcgin.AppConfig.DefaultInt("Pay.timeout", 1800), payInfo.AppId), nil
	}
	return "", toolLib.CreateKcErr(_const.PAY_ERROR)
}

func (c *ccb) PayH5(payInfo *pay2.PayInfo) (string, error) {
	if c.checkIn(payInfo) {
		return lib.CcbPay.Qrurl(payInfo.OrderSn, payInfo.RealAmount, kcgin.AppConfig.DefaultInt("Pay.timeout", 1800), payInfo.AppId), nil
	}
	return "", toolLib.CreateKcErr(_const.PAY_ERROR)
}

func (c *ccb) PayH5New(payInfo *pay2.PayInfo, p *pay2.PayH5) (err error) {
	// if c.checkIn(payInfo) {
	// 	return lib.CcbPay.Qrurl(payInfo.OrderSn, payInfo.RealAmount, kcgin.AppConfig.DefaultInt("Pay.timeout", 1800), payInfo.AppId), nil
	// }
	// return "", toolLib.CreateKcErr(_const.PAY_ERROR)
	return
}

func (c *ccb) PayWxApp(payInfo *pay2.PayInfo) (*gjson.Result, error) {
	if c.checkIn(payInfo) {
		return lib.CcbPay.Wxapp(payInfo.OrderSn, payInfo.RealAmount, kcgin.AppConfig.DefaultInt("Pay.timeout", 1800), payInfo.AppId, payInfo.OpenId), nil
	}
	return nil, toolLib.CreateKcErr(_const.PAY_ERROR)
}

// 微信公众号支付
func (c *ccb) PayWxOfficial(info *pay2.PayInfo) (*gjson.Result, error) {
	return nil, nil
}

func (c *ccb) PayApp(payInfo *pay2.PayInfo) (*gjson.Result, error) {
	if c.checkIn(payInfo) {
		return lib.CcbPay.App(payInfo.OrderSn, payInfo.RealAmount, kcgin.AppConfig.DefaultInt("Pay.timeout", 1800)), nil
	}
	return nil, toolLib.CreateKcErr(_const.PAY_ERROR)
}

func (c *ccb) PayAppSign(payInfo *pay2.PayInfo) (string, error) {
	if c.checkIn(payInfo) {
		return "", nil
	}
	return "", toolLib.CreateKcErr(_const.PAY_ERROR)
}

func (c *ccb) Notify(data string) (*pay2.PayNotify, error) {
	query, _ := url.ParseQuery(data)
	dataMap := map[string]string{}
	for key, value := range query {
		dataMap[key] = value[0]
	}
	// 验签
	if !lib.CcbPay.Valid(dataMap) {
		return nil, toolLib.CreateKcErr(_const.PAY_SIGN_ERROR)
	}
	if query.Get("SUCCESS") != "Y" {
		return nil, toolLib.CreateKcErr(_const.PAY_ERROR)
	}
	info, err := lib.CcbPay.GetOrderInfo(query.Get("ORDERID"))
	if err != nil {
		return nil, toolLib.CreateKcErr(_const.PAY_ERROR)
	}
	payTime := functions.StrtoTime(info.PayTime)
	payType := order.PAY_TYPE_YUAN
	switch query.Get("ACC_TYPE") {
	case "WX":
		payType = order.PAY_TYPE_WX
	case "AL":
		payType = order.PAY_TYPE_ALI
	}

	return &pay2.PayNotify{
		OrderSn:    query.Get("ORDERID"),
		PayTime:    payTime,
		PayAmount:  info.Amount,
		PayFee:     info.Fee,
		PaySn:      info.PaySn,
		PayStatus:  pay2.PAY_Suc,
		PayChannel: order.PAY_CHANNEL_ccb,
		PayType:    payType,
	}, nil
}

//异步回调响应
func (c *ccb) NotifyResponse(ctx context.Context, args *pay2.ArgsNotify) (*pay2.ReplyNotifyResponse, error) {
	return nil, nil
}

func (c *ccb) checkIn(payInfo *pay2.PayInfo) bool {
	// 商家收取 协会存管
	payLists := []lib.PayList{
		{lib.CcbPay.Merchantid, payInfo.BusAmount},
	}
	// 保险公司分账
	if insureAmount, err := decimal.NewFromString(payInfo.InsureAmount); err == nil {
		if !insureAmount.IsZero() {
			payLists = append(payLists, lib.PayList{c.getPolicyMerchantId(payInfo), payInfo.InsureAmount})
		}
	}
	// 续保分账
	if renewInsureAmount, err := decimal.NewFromString(payInfo.RenewInsureAmount); err == nil {
		if !renewInsureAmount.IsZero() {
			payLists = append(payLists, lib.PayList{c.getRenewPolicyMerchantId(payInfo), payInfo.RenewInsureAmount})
		}
	}
	// 平台分账
	if platformAmount, err := decimal.NewFromString(payInfo.PlatformAmount); err == nil {
		if !platformAmount.IsZero() {
			payLists = append(payLists, lib.PayList{kcgin.AppConfig.String("ccbpay.plantMerchantId"), payInfo.PlatformAmount})
		}
	}
	return lib.CcbPay.CheckIn(payInfo.OrderSn, &payLists)
}

// 获取保险公司商户号
func (c *ccb) getPolicyMerchantId(payInfo *pay2.PayInfo) string {
	return kcgin.AppConfig.String("ccbpay.renewPolicyMerchantId")
}

// 获取续保公司商户号
func (c *ccb) getRenewPolicyMerchantId(payInfo *pay2.PayInfo) string {
	return kcgin.AppConfig.String("ccbpay.renewPolicyMerchantId")
}

// 获取支付成功后金额处理
func (c *ccb) PayFund(notify *pay2.PayNotify, bill *order.ReplyGetOrderSplitBill) []bus.FundRecordItem {
	return []bus.FundRecordItem{
		{
			OrderSn:  notify.OrderSn,
			Amount:   notify.PayAmount,
			FundType: bus.FUND_TYPE_pay_in,
		}, {
			OrderSn:  notify.OrderSn,
			Amount:   notify.PayFee,
			FundType: bus.FUND_TYPE_bankfee_out,
		}, {
			OrderSn:  notify.OrderSn,
			Amount:   decimal.NewFromFloat(bill.InsureAmount).String(),
			FundType: bus.FUND_TYPE_insurance_out,
		}, {
			OrderSn:  notify.OrderSn,
			Amount:   decimal.NewFromFloat(bill.RenewInsureAmount).String(),
			FundType: bus.FUND_TYPE_reinsurance_out,
		}, {
			OrderSn:  notify.OrderSn,
			Amount:   decimal.NewFromFloat(bill.PlatformAmount).String(),
			FundType: bus.FUND_TYPE_plat_out,
		},
	}
}

// 获取清分金额
func (c *ccb) GetFundAmount(notify *pay2.PayNotify, bill *order.ReplyGetOrderSplitBill) string {
	fee, _ := decimal.NewFromString(notify.PayFee)
	return decimal.NewFromFloat(bill.BusAmount).Sub(fee).String()
}

// 获取支付方式
func (c *ccb) GetType() int {
	return order.PAY_CHANNEL_ccb
}

// 支付清分数据前置处理
func (c *ccb) AgentChannel(busClearingModel *models.BusClearingModel, list map[string]interface{}) (id int, err error) {
	clearingCcbpayModel := new(models.BusClearingCcbpayModel).Init(busClearingModel.Model.GetOrmer())
	res := clearingCcbpayModel.FindByBusIdAndStatus(list[busClearingModel.Field.F_bus_id], pay2.CLEAR_STATUS_none)
	if len(res) > 0 {
		// 清分金额单次汇总
		upRes, err := clearingCcbpayModel.UpdateByIdAndStatus(res[clearingCcbpayModel.Field.F_id], pay2.CLEAR_STATUS_none, map[string]interface{}{
			clearingCcbpayModel.Field.F_amount:            []interface{}{"inc", list[busClearingModel.Field.F_amount]},
			clearingCcbpayModel.Field.F_depository_amount: []interface{}{"inc", list[busClearingModel.Field.F_depository_amount]},
			clearingCcbpayModel.Field.F_usable_amount:     []interface{}{"inc", list[busClearingModel.Field.F_usable_amount]},
		})
		if err != nil || upRes != 1 {
			return 0, toolLib.CreateKcErr(_const.PAY_ERROR)
		}
		id, err = strconv.Atoi(res[clearingCcbpayModel.Field.F_id].(string))
		if err != nil {
			return 0, toolLib.CreateKcErr(_const.PAY_ERROR)
		}
	} else {
		id = clearingCcbpayModel.Insert(map[string]interface{}{
			clearingCcbpayModel.Field.F_bus_id:            list[busClearingModel.Field.F_bus_id],
			clearingCcbpayModel.Field.F_amount:            list[busClearingModel.Field.F_amount],
			clearingCcbpayModel.Field.F_depository_amount: list[busClearingModel.Field.F_depository_amount],
			clearingCcbpayModel.Field.F_usable_amount:     list[busClearingModel.Field.F_usable_amount],
			clearingCcbpayModel.Field.F_create_time:       time.Now().Unix(),
		})
		if id == 0 {
			return 0, toolLib.CreateKcErr(_const.PAY_ERROR)
		}
	}
	return id, nil
}

// 执行清分任务
func (c *ccb) RunAgent(ctx context.Context) {
	busClearingCcbpayModel := new(models.BusClearingCcbpayModel).Init()
	busClearingCcbpayBatchModel := new(models.BusClearingCcbpayBatchModel).Init(busClearingCcbpayModel.Model.GetOrmer())
	depos := new(bus2.Depos).Init()
	replyDeposCcbInfos := []bus.ReplyDeposCcbInfo{}

	linCount := 100

	proxyNum := kcgin.AppConfig.String("ccbpay.custody.proxyNum")
	payAccountNo := kcgin.AppConfig.String("ccbpay.custody.payAccountNo")
	payAccount := kcgin.AppConfig.String("ccbpay.custody.payAccount")

	for true {
		if listsLen := c.doAgent(ctx, busClearingCcbpayModel, linCount, depos, replyDeposCcbInfos, proxyNum,
			payAccountNo, payAccount, busClearingCcbpayBatchModel); listsLen != linCount {
			break
		}
	}
}

// 循环处理待清分数据
func (c *ccb) doAgent(ctx context.Context, busClearingCcbpayModel *models.BusClearingCcbpayModel, linCount int, depos *bus2.Depos,
	replyDeposCcbInfos []bus.ReplyDeposCcbInfo, proxyNum, payAccountNo, payAccount string,
	busClearingCcbpayBatchModel *models.BusClearingCcbpayBatchModel) (listsLen int) {
	lists := busClearingCcbpayModel.GetListsByStatus(pay2.CLEAR_STATUS_none, linCount)
	listsLen = len(lists)
	if listsLen == 0 {
		return
	}
	busIds := functions.ArrayValue2Array(busClearingCcbpayModel.Field.F_bus_id, lists)
	if err := depos.GetDeposCcbInfos(ctx, &busIds, &replyDeposCcbInfos); err != nil {
		return
	}
	res := map[int]bus.ReplyDeposCcbInfo{}
	for _, replyDeposCcbInfo := range replyDeposCcbInfos {
		res[replyDeposCcbInfo.BusId] = replyDeposCcbInfo
	}
	totalAmount := decimal.Zero
	content := ""
	index := 0
	upIds := []string{}
	for _, list := range lists {
		busId, _ := strconv.Atoi(list[busClearingCcbpayModel.Field.F_bus_id].(string))
		ccbInfo, ok := res[busId]
		if !ok {
			utils.Logerr.Printf("商户建行存管账户信息未查到:bus_id:%v", busId)
			busClearingCcbpayModel.UpdateByIdAndStatus(list[busClearingCcbpayModel.Field.F_id], pay2.CLEAR_STATUS_none, map[string]interface{}{
				busClearingCcbpayModel.Field.F_status:    pay2.CLEAR_STATUS_fail,
				busClearingCcbpayModel.Field.F_error_msg: "未找到商户存管账户信息",
			})
			continue
		}
		if rowCount, err := busClearingCcbpayModel.UpdateByIdAndStatus(list[busClearingCcbpayModel.Field.F_id], pay2.CLEAR_STATUS_none, map[string]interface{}{
			busClearingCcbpayModel.Field.F_status:       pay2.CLEAR_STATUS_ing,
			busClearingCcbpayModel.Field.F_merchant_id:  ccbInfo.MerchantId,
			busClearingCcbpayModel.Field.F_account_name: ccbInfo.AcctName,
			busClearingCcbpayModel.Field.F_account_no:   ccbInfo.AcctNo,
			busClearingCcbpayModel.Field.F_order_no:     index + 1,
		}); err != nil || rowCount == 0 {
			utils.Logerr.Printf("数据库操作失败:bus_id:%v", busId)
			continue
		}
		index += 1
		content = fmt.Sprintf("%s\n%d|%v|%v|%v|%v|%v|%v|", content, index, payAccountNo, payAccount, ccbInfo.MerchantId, ccbInfo.AcctNo, ccbInfo.AcctName, list[busClearingCcbpayModel.Field.F_amount])
		totalAmount = totalAmount.Add(decimal.RequireFromString(list[busClearingCcbpayModel.Field.F_amount].(string)))

		upIds = append(upIds, list[busClearingCcbpayModel.Field.F_id].(string))
	}
	content = fmt.Sprintf("%v|%v|%v|\n%v", proxyNum, totalAmount, index, content)
	fileName := fmt.Sprintf("%v_%s.txt", lib.Worker.GetId(), time.Now().Format("2006-01-02"))

	upload, err := lib.CcbCustody.FundUpload(fileName, content)
	if err != nil {
		utils.Logerr.Printf("文件上传失败，err:%v", err)
		if _, err := busClearingCcbpayModel.UpdateByIdsAndStatus(upIds, pay2.CLEAR_STATUS_ing, map[string]interface{}{
			busClearingCcbpayModel.Field.F_status:    pay2.CLEAR_STATUS_fail,
			busClearingCcbpayModel.Field.F_error_msg: "文件上传失败",
		}); err != nil {
			utils.Logerr.Printf("数据库操作失败:busClearingCcbpayModel:ids:%v", upIds)
			return
		}
		return
	}
	now := time.Now()
	fileId := busClearingCcbpayBatchModel.Insert(map[string]interface{}{
		busClearingCcbpayBatchModel.Field.F_file_name: upload.Name,
		busClearingCcbpayBatchModel.Field.F_file_path: upload.Path,
		busClearingCcbpayBatchModel.Field.F_date_ymd:  now.Format("20060102"),
		busClearingCcbpayBatchModel.Field.F_date_time: now.Unix(),
	})
	if fileId == 0 {
		utils.Logerr.Printf("数据库操作失败:busClearingCcbpayBatchModel:ids:%v", upIds)
		return
	}
	fund, err := lib.CcbCustody.Fund(strconv.FormatInt(lib.Worker.GetId(), 10), upload.Path, upload.Name, totalAmount.String(), index)
	if err != nil {
		utils.Logerr.Printf("清分请求失败，err:%v", err)
		if _, err := busClearingCcbpayModel.UpdateByIdsAndStatus(upIds, pay2.CLEAR_STATUS_ing, map[string]interface{}{
			busClearingCcbpayModel.Field.F_status:    pay2.CLEAR_STATUS_fail,
			busClearingCcbpayModel.Field.F_error_msg: "清分请求失败",
		}); err != nil {
			utils.Logerr.Printf("清分请求失败:ids:%v", upIds)
			return
		}
		return
	}
	if rowCount, err := busClearingCcbpayBatchModel.UpdateById(fileId, map[string]interface{}{
		busClearingCcbpayBatchModel.Field.F_batch_no: fund.Batno,
	}); err != nil || rowCount == 0 {
		utils.Logerr.Printf("数据库操作失败:busClearingCcbpayBatchModel:fileId:%v,Batno:%v", fileId, fund.Batno)
		return
	}
	if _, err := busClearingCcbpayModel.UpdateByIdsAndStatus(upIds, pay2.CLEAR_STATUS_ing, map[string]interface{}{
		busClearingCcbpayModel.Field.F_batch_no: fund.Batno,
	}); err != nil {
		utils.Logerr.Printf("数据库操作失败:ids:%v", upIds)
		return
	}
	return
}

func (c *ccb) AgentChannelPlat(platClearingModel *models.PlatformClearingModel, list map[string]interface{}) (id int, err error) {
	return
}
func (c *ccb) AgentChannelInsure(insureClearingModel *models.InsureClearingModel, list map[string]interface{}) (id int, err error) {
	return
}
func (c *ccb) AgentChannelRenewInsure(renewInsureClearingModel *models.RenewInsureClearingModel, list map[string]interface{}) (id int, err error) {
	return
}

// 处理清分结果
func (c *ccb) FundAgent(ctx context.Context) (rest bool) {
	rest = true
	busClearingCcbpayBatchModel := new(models.BusClearingCcbpayBatchModel).Init()
	busClearingCcbpayModel := new(models.BusClearingCcbpayModel).Init(busClearingCcbpayBatchModel.Model.GetOrmer())
	busClearingFundRealationModel := new(models.BusClearingFundRealationModel).Init(busClearingCcbpayBatchModel.Model.GetOrmer())
	busClearingModel := new(models.BusClearingModel).Init(busClearingCcbpayBatchModel.Model.GetOrmer())
	rpcFund := new(bus2.Fund).Init()
	reply := false
	linCount := 100
	for true {
		lists := busClearingCcbpayBatchModel.GetListsByStatus(models.STATUS_none, linCount)
		listsLen := len(lists)
		if listsLen == 0 {
			break
		}
		for _, list := range lists {
			result, err := lib.CcbCustody.FundResult("CF"+strconv.FormatInt(lib.Worker.GetId(), 10), list[busClearingCcbpayBatchModel.Field.F_date_ymd].(string), list[busClearingCcbpayBatchModel.Field.F_batch_no].(string))
			if err != nil {
				utils.Logerr.Printf("获取清分结果失败，err:%v", err)
				rest = false
				return
			}
			decodeString, err := base64.StdEncoding.DecodeString(result.FileContent)
			if err != nil {
				utils.Logerr.Printf("清分结果编码错误，err:%v，value:%v", err, result.FileContent)
				continue
			}
			split := strings.Split(string(decodeString), "\n")
			now := time.Now()
			for i, item := range split {
				if i == 0 {
					continue
				}
				value := strings.Split(item, "|")
				if len(value) != 13 {
					continue
				}
				if value[10] == lib.CCB_FUND_suc {
					// 清分成功
					if rowLen, err := busClearingCcbpayModel.UpdateResultAgent(value[0], list[busClearingCcbpayBatchModel.Field.F_batch_no], pay2.CLEAR_STATUS_ing, value[3], map[string]interface{}{
						busClearingCcbpayModel.Field.F_status:     pay2.CLEAR_STATUS_suc,
						busClearingCcbpayModel.Field.F_agent_time: now.Unix(),
					}); err != nil || rowLen == 0 {
						utils.Logerr.Printf("数据库操作失败：busClearingCcbpayModel：err:%v,value:%v", err, list)
						continue
					}
					// 获取清分成功的busId
					findResultAgent := busClearingCcbpayModel.FindResultAgent(value[0], list[busClearingCcbpayBatchModel.Field.F_batch_no], pay2.CLEAR_STATUS_suc, value[3])
					if len(findResultAgent) == 0 {
						utils.Logerr.Printf("清分数据busId获取失败：busClearingCcbpayModel：value:%v", list)
						continue
					}
					busId, _ := strconv.Atoi(findResultAgent[busClearingCcbpayModel.Field.F_bus_id].(string))
					// 商户单日资金结算表状态处理
					if rowLen, err := busClearingModel.UpdateAgent(busId, findResultAgent[busClearingCcbpayModel.Field.F_id], order.PAY_CHANNEL_ccb, pay2.CLEAR_STATUS_ing, map[string]interface{}{
						busClearingModel.Field.F_status: pay2.CLEAR_STATUS_suc,
					}); err != nil || rowLen == 0 {
						utils.Logerr.Printf("商户单日资金结算表状态处理失败：busClearingModel：value:%v", list)
						continue
					}
					// 获取清算数据
					orderSn := "CF" + strconv.FormatInt(lib.Worker.GetId(), 10)
					insId := busClearingFundRealationModel.Insert(map[string]interface{}{
						busClearingFundRealationModel.Field.F_bus_id:            busId,
						busClearingFundRealationModel.Field.F_order_sn:          orderSn,
						busClearingFundRealationModel.Field.F_fund_channel_id:   findResultAgent[busClearingCcbpayModel.Field.F_id],
						busClearingFundRealationModel.Field.F_fund_channel_type: order.PAY_CHANNEL_ccb,
						busClearingFundRealationModel.Field.F_create_time:       now.Unix(),
					})
					if insId == 0 {
						utils.Logerr.Printf("清分realation表插入失败：value:%v", list)
						continue
					}

					fundRecordList := []bus.FundRecordItem{}
					depositoryAmount, err := decimal.NewFromString(findResultAgent[busClearingCcbpayModel.Field.F_depository_amount].(string))
					if err != nil {
						utils.Logerr.Printf("金额转换错误:err:%v,value:%v", err, list)
						continue
					}
					if !depositoryAmount.IsZero() {
						fundRecordList = append(fundRecordList, bus.FundRecordItem{
							OrderSn:  orderSn,
							Amount:   depositoryAmount.String(),
							FundType: bus.FUND_TYPE_depository,
						})
					}
					usableAmount, err := decimal.NewFromString(findResultAgent[busClearingCcbpayModel.Field.F_usable_amount].(string))
					if err != nil {
						utils.Logerr.Printf("金额转换错误:err:%v,value:%v", err, list)
						continue
					}
					if !usableAmount.IsZero() {
						fundRecordList = append(fundRecordList, bus.FundRecordItem{
							OrderSn:  orderSn,
							Amount:   usableAmount.String(),
							FundType: bus.FUND_TYPE_usable,
						})
					}
					if len(fundRecordList) > 0 {
						if err := rpcFund.PayCharge(ctx, &bus.FundRecord{
							BusId:          busId,
							FundRecordList: fundRecordList,
						}, &reply); err != nil {
							utils.Logerr.Printf("资金变动rpc错误:err:%v,value:%v", err, list)
							continue
						}
					}
				} else {
					if rowLen, err := busClearingCcbpayModel.UpdateResultAgent(value[0], list[busClearingCcbpayBatchModel.Field.F_batch_no], pay2.CLEAR_STATUS_ing, value[3], map[string]interface{}{
						busClearingCcbpayModel.Field.F_status:    pay2.CLEAR_STATUS_fail,
						busClearingCcbpayModel.Field.F_error_msg: value[11],
					}); err != nil || rowLen == 0 {
						utils.Logerr.Printf("数据库操作失败：busClearingCcbpayModel：err:%v,value:%v", err, list)
						continue
					}

					// 获取清分成功的busId
					findResultAgent := busClearingCcbpayModel.FindResultAgent(value[0], list[busClearingCcbpayBatchModel.Field.F_batch_no], pay2.CLEAR_STATUS_fail, value[3])
					if len(findResultAgent) == 0 {
						utils.Logerr.Printf("清分数据busId获取失败：busClearingCcbpayModel：value:%v", list)
						continue
					}

					if rowLen, err := busClearingModel.UpdateAgent(findResultAgent[busClearingCcbpayModel.Field.F_bus_id], findResultAgent[busClearingCcbpayModel.Field.F_id], order.PAY_CHANNEL_ccb, pay2.CLEAR_STATUS_ing, map[string]interface{}{
						busClearingModel.Field.F_status: pay2.CLEAR_STATUS_fail,
					}); err != nil || rowLen == 0 {
						utils.Logerr.Printf("商户单日资金结算表状态处理失败：busClearingModel：value:%v", list)
						continue
					}
				}
			}
			if rowLen, err := busClearingCcbpayBatchModel.UpdateByBatchNo(list[busClearingCcbpayBatchModel.Field.F_batch_no].(string), map[string]interface{}{
				busClearingCcbpayBatchModel.Field.F_status: models.STATUS_SUC,
			}); err != nil || rowLen == 0 {
				utils.Logerr.Printf("数据库操作失败：busClearingCcbpayBatchModel：err:%v,BatchNo:%v", err, list[busClearingCcbpayBatchModel.Field.F_batch_no].(string))
				continue
			}

		}

		if listsLen != linCount {
			break
		}
	}
	return
}

func (c *ccb) GetInsureFund() bool {
	return false
}
